/** **************************************************
 * Copyright:   Copyright (c) 2008
 * Company:    cl
 * @author     caoxl
 * @version    1.0
 * @see
 HISTORY
 *  2008-7-1 caoxl Create File
 ************************************************* */
package com.bfsuol.bfsuolframework.core.dao;

import com.bfsuol.bfsuolframework.core.controller.support.Pagination;
import com.bfsuol.bfsuolframework.core.controller.support.QueryParam;
import com.bfsuol.bfsuolframework.core.dao.support.HqlParameter;
import com.bfsuol.bfsuolframework.core.entity.Entity;

import java.util.List;

public interface DAO<E extends Entity> {
	
	public Long save(E obj);
	
	public void update(E obj);
	
	public Long saveOrUpdate(E obj);
	
	public void merge(E obj);
	
	public void delete(E obj);
	
	public void delete(Long obj);
	
	public void evict(E obj);
	
	public void clear();
	
	public E getById(Long id);

	public E loadById(Long id);

	public void flush();
	
	public void batchSave(List<E> objects);
	
	public void batchUpdate(List<E> objects);
	
	public void batchSaveOrUpdate(List<E> objects);
	    
	public void batchRemove(List<E> objects);

	public List<E> findAll();
	
	
	//通过Criteria进行数据苦操作
	public Pagination getPage(QueryParam query, Pagination page);
	
	public Pagination getPage(String hql, HqlParameter parameters, Pagination page);
	
	public List<E> findAll(final QueryParam query);
        
	public List<E> findAll(final QueryParam query, int firstResult, int maxResult);
	
	public int getCount(final QueryParam query);
	
	/**
	 * 判断属性有无相同的值，用作更新
	 * @param propertyName 属性名称
	 * @param value 判断的值
	 * @param excludePrimaryKey 排除的主键
	 * @return
	 */
	public boolean isPropertyUnique(final String propertyName, final Object value, final Long excludePrimaryKey);
	
	/**
	 * 判断属性有无相同的值，用作更新
	 * @param propertyName 属性名称
	 * @param value 判断的值
	 * @param excludePrimaryKey 排除的主键
	 * @param includecColumn 所在的列
	 * @param includecColumnValue 所在列判断的值
	 * @return
	 */
	public boolean isPropertyUnique(final String propertyName, final Object value, final Long excludePrimaryKey, final String includecColumn, final Long includecColumnValue);
}
